/* eslint-disable no-unused-vars */
<template>
  <div>
    <el-menu
      :default-active="path"
      router
      mode="horizontal"
      background-color="white"
      text-color="#222"
      active-text-color="red"
      style="min-width: 1300px">
      <el-menu-item v-for="(item,i) in navList" :key="i" :index="item.name">
        {{ item.navItem }}
      </el-menu-item>
      <span style="position: absolute;padding-top: 20px;right: 43%;font-size: 20px;font-weight: bold">实验室 => 综合事务</span>
      <el-input
        placeholder="暂时还不可用~"
        prefix-icon="el-icon-search"
        size="medium"
        style="width: 300px;position:absolute;margin-top: 12px;right: 18%"
        v-model="keywords">
      </el-input>
      <div class="render" v-if="!islogin">
        <a href="/common/login">登陆</a>/
        <a href="/common/register">注册</a>
      </div>
        <div class="render" v-else>
          <a href="javascript:void(0);" @click="loginout" style="index:100">{{fromdate.username}} {{fromdate.name}}，你好/退出</a>
        </div>

    </el-menu>

  </div>
</template>

<script>
  export default {
    name: 'NavMenu',
    data () {
      return {
        fromdate: {
          username: '092218124',
          name: '朱耀威'
        },
        navList: [
          {name: '/index', navItem: '首页'},
          {name: '/jotter', navItem: '笔记本'},
          {name: '/library', navItem: '图书馆'},
          {name: '/homework', navItem: '作业'},
          {name: '/admin/dashboard', navItem: '管理中心', row: 'admin'}
        ],
        islogin: false,
        keywords: '',
        path: ''
      }
    },
    created: function () {
      // 初始化成员
      this.fromdate.username = this.$store.state.homework.username
      this.fromdate.name = this.$store.state.homework.name
      if (this.$store.state.homework.token && this.$store.state.homework.token !== '') {
        this.islogin = true
      } else {
        this.islogin = false
      }
      // 如果当前是admin权限删除 管理页面
      if (!this.$store.state.homework.su) {
        for (var index in this.navList) {
          if (typeof (this.navList[index].row) !== 'undefined' && this.navList[index].row === 'admin') {
            this.navList.splice(index, 1)
          }
        }
      }
    },
    mounted: function () {
      // 获得第一级路由，以设置导航栏高亮
      var x = this.$route.path.indexOf('/', 1)
      if (x !== -1) {
        this.path = this.$route.path.substring(0, x)
      } else {
        this.path = this.$route.path
      }
    },
    computed: {
      hoverBackground () {
        return '#ffd04b'
      }
    },
    methods: {
      loginout () {
        let that = this
        this.$store.commit('clearhomelist')
         this.intervalId = setInterval(() => {
            that.islogin = false
          }, 400)
      }
    }
  }
</script>

<style scoped>
  a{
    text-decoration: none;
  }

  span {
    pointer-events: none;
  }
  .render{
    position: absolute;padding-top: 20px;right: 8%;font-size: 10px;font-weight: bold
  }

</style>
